package com.wenzhan.service;

import com.wenzhan.service.entity.UserEntity;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class TestDemo2 {
    public static void main(String[] args) {
        ArrayList<UserEntity> userEntities = new ArrayList<>();
        userEntities.add(new UserEntity("mayikt", 20));
        userEntities.add(new UserEntity("meite", 28));
        userEntities.add(new UserEntity("zhangsan", 35));
        userEntities.add(new UserEntity("xiaowei", 16));
        userEntities.add(new UserEntity("xiaoweimei", 15));
        userEntities.add(new UserEntity("Huawei", 22));
        UserEntity userEntity = userEntities.stream().max((o1, o2) -> o1.getAge() - o2.getAge()).get();
        System.out.println("Max age is " + userEntity.toString());
        UserEntity minUserEntity = userEntities.stream().min(((o1, o2) -> o1.getAge() - o2.getAge())).get();
        System.out.println("min age is " + minUserEntity);
        boolean b = userEntities.stream().anyMatch(userEntity1 -> "Huawei".equals(userEntity1.getUserName()));
        System.out.println("is has huawei :" + b);
        boolean b1 = userEntities.stream().allMatch(userEntity12 -> "Huawei".equals(userEntity12.getUserName()));
        System.out.println("is all huawei :" + b1);
        // 分页功能:跳过前两条数据后取五条数据
        System.out.println("开始分页了呀-------》");
        userEntities.stream().skip(2).limit(5).forEach(userEntity1 -> System.out.println(userEntity1));
        // Java排序，默认为升序
        System.out.println("开始升序了呀-------》");
        userEntities.stream().sorted((o1, o2) -> o1.getAge() - o2.getAge()).forEach(userEntity1 -> System.out.println(userEntity1));

        System.out.println("开始降序了呀-------》");
        userEntities.stream().sorted((o1, o2) -> o2.getAge() - o1.getAge()).forEach(userEntity1 -> System.out.println(userEntity1));
        System.out.println("开始需求了呀-------》");
        userEntities.stream().sorted(((o1, o2) -> o2.getAge()- o1.getAge())).filter(userEntity1 -> userEntity1.getUserName().contains("mayi")).limit(2).forEach(userEntity1 -> System.out.println(userEntity1));
    }
}
